package com.yang.biz.modular.http.manager;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import org.springframework.stereotype.Component;

/**
 * @author: yangjianzhi
 * @version1.0
 */
@Component
public class StationDataCollectHttp extends CustomHttpRequest {

    private String baseURL = "http://120.79.221.57/stationDataCollect/";

    private final String appId = "J8VdVDTw";

    private final String random = "12323";

    public StationDataCollectHttp() {
        super.baseURL = baseURL;
        this.login();
    }

    private void login() {
        JSONObject data = this.post("/login")
                .body("appId", appId
                        , "random", random
                        , "sign", "fe0798102cb99d6298d0f76afd2d1e9a909467313384fe98898eabc6fbd88ad4")
                .executeObject();
        if (ObjectUtil.isNotEmpty(data)) {
            String accessToken = data.getStr("accessToken");
            if (StrUtil.isNotBlank(accessToken)) {
                this.setToken(accessToken);
            }
        }
    }
}
